/*
 * relative     : \src\hooks\useDynamicForm.ts
 * Author       : 郭鹏超
 * Date         : 2024-11-30 09:15
 * LastEditors  : 郭鹏超
 * LastEditTime : 2025-02-28 11:14
 * Description  :公共获取评估模板信息
 * CodeIterationRecord:
 */
import type { dynamicFormData, formAttribute } from "zhytech-ui";
const { userStore } = useStore();
const templateCodeID = ref<string>();
const useDynamicForm = <T>() => {
  const caseToAssessInfo = ref<Record<string, any>>({});
  /**
   * @description: 获取模板对应CaseToAssess信息
   * @param templateType
   * @return
   */
  const getCaseToAssessTemplateInfo = (templateType: string) => {
    let param = {
      caseManagementID: userStore.currentCaseManagement.caseManagementID,
      templateType
    };
    assessTemplateService.getCaseToAssessTemplateInfo(param).then((res: any) => {
      caseToAssessInfo.value = res ?? {};
    });
  };
  const formData = ref<dynamicFormData<formAttribute>>({
    datas: {},
    components: [],
    props: {} as formAttribute
  });
  /**
   * @description: 重置表单数据
   */
  const resetFormData = () => {
    formData.value = {
      datas: {},
      components: [],
      props: {} as formAttribute
    };
  };

  const dynamicFormInsertMySql = ref<string>("");
  /**
   * @description: 根据templateCodeID下载脚本
   * @param templateCodeID
   * @return
   */
  const getDynamicFormInsertMySql = () => {
    dynamicFormService.getDynamicFormInsertMySql({ templateCodeID: templateCodeID.value }).then((res: string) => {
      dynamicFormInsertMySql.value = res;
    });
  };
  return {
    caseToAssessInfo,
    templateCodeID,
    formData,
    dynamicFormInsertMySql,
    getCaseToAssessTemplateInfo,
    resetFormData,
    getDynamicFormInsertMySql
  };
};

export { useDynamicForm };
